package cn.itcast.order.service.impl;

import cn.itcast.feign.clients.UserFeign;

import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.service.OrderService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderServiceImpl implements OrderService {
	
	@Resource
	private OrderMapper orderMapper;
	//@Resource
	//RestTemplate restTemplate;
	@Autowired
	private UserFeign userFeign;
	
	@SneakyThrows
	@Override
	public Order queryOrderById(Long orderId) {
		//1.查询订单
		Order order = orderMapper.findById(orderId);
		//2.查询用户
		//URI url = new URI("http://userservice/user/" + order.getUserId());
		//User user = restTemplate.getForObject(url, User.class);
		//3.构建订单
	     //User user=userFeign.queryById(order.getUserId());
		Long userId=order.getUserId();
		User user=userFeign.queryById(userId);
		order.setUser(user);
		return order;
	}
}
